import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Leet46 {
    public static void main(String[] args) {
        int[] a = {0,1};
        Leet46 l = new Leet46();
        List<List<Integer>> list = l.permute(a);
        for (List<Integer> li:list){
            for (int t:li){
                System.out.print(t);
            }
            System.out.println();
        }
    }

    public List<List<Integer>> permute(int[] nums) {
        int[] vis = new int[nums.length];
        List<Integer> temp = new ArrayList<>();
        List<List<Integer>> res = new ArrayList<>();
        dfs(nums,vis,temp,nums.length,res);
        return res;
    }
    public static void dfs(int[] nums,int[] vis,List<Integer> temp,int length,List<List<Integer>> res){
        if (temp.size()==nums.length){
            res.add(new ArrayList<>(temp));
            return;
        }
        for (int i = 0; i < length; i++) {
            if (vis[i]==1)
                continue;
            vis[i] = 1;
            temp.add(nums[i]);
            dfs(nums,vis,temp,length,res);
            vis[i] = 0;
            temp.remove(temp.size()-1);
        }

    }


}
